package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyWishListQueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.query.UserProfilesQueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JsonResult;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * session资源过滤器
 * */
@RestController
@RequestMapping("/usersProfilers")
public class UserProfilersController {

    @Autowired
    private IUserService userService;
    @Autowired
    private ITravelService travelService;
    @Autowired
    private IStrategyWishListService strategyWishListService;
    @Autowired
    private IStrategyCommentService strategyCommentService;

    /**
     * 查询用户个人资料
     * @param id 用户id
     * @return
     */
    @GetMapping("/users/{userId}")
    public User queryforUserProfilers(@PathVariable Long id) {
        User userProfilers= userService.queryforUserProfilers(id);
        return userProfilers;
    }

    /**
     * 查询用户游记
     * @param qo
     * @return
     */
    @GetMapping("/travels/{userId}")
    public PageInfo queryTravels(UserProfilesQueryObject qo){
        qo.setOrderBy("createTime desc");
        PageInfo travels = travelService.queryforTravels(qo);
        return travels;
    }

    /**
     * 查询用户是否加入当前功能为旅行单
     * @param qo
     * @return
     */
    @GetMapping("/StrategyWishList/{userId}/{strategyId}")
    public Boolean queryStrateg(StrategyWishListQueryObject qo){
        return strategyWishListService.queryforStrategyWishList(qo);
    }
    /**
     * 查询用户所有的旅行单
     * @param qo
     * @return
     */
    @GetMapping("/StrategyWishList/{userId}")
    public PageInfo queryStrategies(StrategyWishListQueryObject qo){
        PageInfo strategies = strategyWishListService.queryforall(qo);
        return strategies;
    }

    /**
     * 添加旅行单
     * @param qo
     * @return
     */
    @PostMapping("/StrategyWishList/{userId}/{strategyId}")
    public JsonResult save(StrategyWishListQueryObject qo){
        strategyWishListService.savestrategywishList(qo);
        return new JsonResult();
    }

    /**
     * 查询用户个攻略评论
     * @param qo
     * @return
     */
    @GetMapping("/strategyComments/{userId}")
    public PageInfo queryStrategComments(UserProfilesQueryObject qo){
        qo.setOrderBy("createTime desc");
        PageInfo strategyComments = strategyCommentService.queryforStrategyComments(qo);
        return strategyComments;
    }

}
